Tag Link | [Net->Bind] | Category | Networking |
---|---|---|---|
Type | Member | Source Available | Yes |
Support | Preferred | Version | 7.0 |
Change | Unchanged | Data Source | Any |
Output Type | None | Security | None |
Implementation | LCAPI | Sets | Lasso 8.5, Lasso 8.0, Lasso 7.0 |
[Net->Bind] is used with TCP or UDP listeners to specify what port they will listen on.
TCP listeners must first use [Net->SetType] to set the type to [Net_TypeTCP]. [Net->Bind] is then used to set the port that will be listened on. The object is put into listening mode using [Net->Listen] and invidivual incoming connections are accepted using [Net->Accept].
UDP listeners must first use [Net->SetType] to set the type to [Net_TypeUDP]. [Net->Bind] is then used to set the port that will be listened on. [Net->ReadFrom] is used to accept incoming connections. The return value includes the data that was sent by the remote host and the IP address of the remote host.
<?LassoScript
Variable: 'Listener' = (Net);
$Listener->(Bind: 8000);
$Listener->(Listen);
Variable: 'Connection' = $Listener->Accept;
...
$Connection->Close;
$Listener->Close;
?>
<?LassoScript
Variable: 'Listener' = (Net);
$Listener->(SetType: Net_TypeUDP);
$Listener->(Bind: 8000);
Variable: 'Result' = $Listener->(ReadFrom: 32768);
...
$Listener->Close;
?>
Required Parameters | |
---|---|
Port | The port number to bind the listener to. |
To listen for incoming TCP connections:
Use the [Net] type and its member tags to establish a TCP listener. The following example listens on port 80 for incoming TCP traffic. The [Net->Accept] tag returns a new connection and the IP address of the local machine and the remote machine are reported.
[Variable: 'myListener' = (Net)]
[$myListener->(Bind: 80)]
[$myListener->(Listen)]
[Variable: 'myConnecton' = $myListener->(Accept)]
Local: [Output: $myConnection->(LocalAddress)]
Remote: [Output: $myConnection->(RemoteAddress)]
[Variable: 'Input' = $myConnection->(Read: 32768)]
...
[$myConnection->(Close)]
[$myListener->(Close)]
Local: 127.0.0.1
Remote: www.example.com